﻿using Microsoft.AspNetCore.Mvc;
using MiniFox.Infrastructure;
using MiniFox.Scripting;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;

namespace MiniFox.Platform.Web
{
    /// <summary>
    /// 
    /// </summary>
    [PublicAccessible]
    public class ScriptController : MvcControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Response<List<object>> Functions()
        {
            var funcList = new List<object>();
            foreach (FunctionBase function in ScriptEngine.Container.Functions)
            {
                funcList.Add(new { Name = function.Name, Description = function.Description, Expression = ScriptEngine.CreateFunctionExpression(function.Name) });
            }
            var response = funcList.CreateResponse();
            
            return response;
        }
    }
}
